home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / BoxTex / Textures.c < prev    next >
Encoding:
Text File  |  1997-08-14  |  3.6 KB  |  125 lines  |  [TEXT/CWIE]

  1. // routines to allow us to put texture maps on a parameterized group
  2. //
  3. // ©1994-95 Apple Computer Inc., All Rights Reserved
  4.  
  5. #include <QuickDraw.h>
  6. #include "QD3D.h"
  7. #include "QD3DGroup.h"
  8. #include "QD3DShader.h"
  9.  
  10.  
  11. #include "PictRead.h"        // this is a library file from QD3D applications folder
  12. #include "Textures.h"
  13.  
  14. TQ3Status AddTextureToGroup( TQ3GroupObject    theGroup, TQ3StoragePixmap *textureImage)
  15. {
  16.     TQ3TextureObject    textureObject;
  17.     TQ3GroupPosition     position;
  18.     TQ3Object            firstObject;
  19.     
  20.     textureObject = Q3PixmapTexture_New(textureImage);
  21.     
  22.     /*
  23.      * We dispose of the image field here, if you need it again, just get it from the 
  24.      * textureObject using Q3PixmapTexture_GetPixmap.
  25.      */
  26.     Q3Object_Dispose(textureImage->image) ;
  27.     
  28.     if( textureObject ) {
  29.         if( Q3Object_IsType(theGroup, kQ3GroupTypeDisplay) == kQ3True) {
  30.             Q3Group_GetFirstPosition(theGroup, &position);
  31.     
  32.             Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  33.     
  34.             if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  35.                 TQ3TextureObject    oldTextureObject;
  36.                 TQ3StoragePixmap oldTextureImage;
  37.                         
  38.                 Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  39.                 Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  40.                 
  41.                 Q3Object_Dispose(oldTextureObject);
  42.                 Q3TextureShader_SetTexture(firstObject, textureObject);
  43.                 Q3Object_Dispose(textureObject);
  44.             } else {
  45.                 TQ3ShaderObject textureShader;
  46.                 
  47.                 textureShader = Q3TextureShader_New(textureObject);
  48.                 Q3Object_Dispose(textureObject);
  49.                 //Q3Group_SetPositionObject(theGroup, position, theDocument->textureShader);
  50.                 Q3Group_AddObjectBefore(theGroup, position, textureShader);
  51.                 Q3Object_Dispose(textureShader);
  52.             }
  53.             
  54.             Q3Object_Dispose(firstObject);
  55.         } else if( Q3Object_IsType(theGroup, kQ3DisplayGroupTypeOrdered) == kQ3True) {
  56.             TQ3ShaderObject textureShader;
  57.             
  58.             Q3Group_GetFirstPositionOfType(
  59.                 theGroup,
  60.                 kQ3ShapeTypeShader, &position);    
  61.             
  62.             if( position ) {
  63.                 Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  64.     
  65.                 if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  66.                     TQ3TextureObject    oldTextureObject;
  67.                     TQ3StoragePixmap oldTextureImage;
  68.                     
  69.                     Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  70.                     Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  71.                     
  72.                     Q3Object_Dispose(oldTextureObject);
  73.                     Q3TextureShader_SetTexture(firstObject, textureObject);
  74.                     Q3Object_Dispose(textureObject);
  75.                 } else {
  76.                     textureShader = Q3TextureShader_New(textureObject);
  77.                     if( textureShader ) {
  78.                         Q3Object_Dispose(textureObject);
  79.                         Q3Group_SetPositionObject(theGroup, position, textureShader);
  80.                         Q3Object_Dispose(textureShader);
  81.                     } else {
  82.                         return(kQ3Failure);
  83.                     }
  84.                 }
  85.             } else {
  86.                 textureShader = Q3TextureShader_New(textureObject);
  87.                 if( textureShader ) {
  88.                     Q3Object_Dispose(textureObject);
  89.                     Q3Group_AddObject(theGroup, textureShader);
  90.                     Q3Object_Dispose(textureShader);
  91.                 } else {
  92.                     return(kQ3Failure);
  93.                 }
  94.             }
  95.             
  96.         }
  97.     return(kQ3Success);
  98.     } else {
  99.         return(kQ3Failure);
  100.     }
  101. }
  102.  
  103. void PictureFileToPixmap( TQ3StoragePixmap *bMap )
  104. {
  105.     PicHandle             thePicture = nil;
  106.     
  107.     if((thePicture = GetPICTFile()) != NULL ) {
  108.     
  109.         LoadMapPICT( thePicture, 
  110.                      0L,
  111.                      (unsigned long)((**thePicture).picFrame.right - (**thePicture).picFrame.left),
  112.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  113.                      bMap)    ;
  114.         
  115.     }
  116. }
  117.  
  118. void TextureGroup( TQ3GroupObject    theGroup)
  119. {
  120.     TQ3StoragePixmap         myMap ;
  121.     
  122.     PictureFileToPixmap( &myMap ) ;
  123.     if( myMap.image != NULL )
  124.         AddTextureToGroup( theGroup, &myMap ) ;
  125. }